﻿using System;

namespace Assets.Scripts.Example
{
    public class MainBtn : BaseBehaviour
    {
        private Action<EnumExample> _clickAction;

        private EnumExample _exampleType;
        public UIButton m_Btn;
        public UILabel m_BtnLabel;

        public void Init(int index, Action<EnumExample> clickAction)
        {
            _exampleType = ExampleHelper.GetExampleTypeByIndex(index);
            _clickAction = clickAction;
            m_BtnLabel.text = ExampleHelper.GetMainBtnLabel(_exampleType);
            EventDelegate.Set(m_Btn.onClick, OnBtnClick);
        }

        private void OnBtnClick()
        {
            if (_clickAction != null)
            {
                _clickAction(_exampleType);
            }
        }
    }
}